Learn R Programming

micropan (version 1.0)

readFasta and writeFasta: Read and write biological sequence files.

Description

Reads and writes biological sequences (DNA, RNA, protein) in the commonly used FASTA format.

Usage

readFasta(in.file) writeFasta(fdta,out.file,width=80)

Arguments

in.file
url/directory/name of FASTA file to read.
fdta
A Fasta object with the columns Header and Sequence, see ‘Details’ below.
out.file
Name of FASTA-file to create.
width
Number of characters per line in the FASTA format.

Value

readFasta returns a Fasta object with the contents of the FASTA file. This is a small extension to a data.frame and contains two columns of text. The first, named Header, contains the headerlines and the second, named Sequence, contains the sequences.writeFasta produces a FASTA file.

Details

These functions handle input/output of sequences in the commonly used FASTA format. The sequences are stored in a Fasta object. This is a small (S3) extension of a data.frame containing two text-columns named Header and Sequence. If other columns are present, these will be ignored by writeFasta.

The Fasta object can be treated as a data.frame, but the generic functions plot.Fasta, summary.Fasta and str.Fasta are defined. The data.frame property makes it straightforward to manipulate all headers or all sequences, or to extract or delete entries (rows), or to merge several data sets using rbind.

See Also

plot.Fasta, summary.Fasta, str.Fasta.

Examples

Run this code
# Reading a FASTA-file from the package extdata/ folder
# We need to uncompress it first...
extdata.path <- file.path(path.package("micropan"),"extdata")
filenames <- "Mpneumoniae_309_protein.fsa"
pth <- lapply( file.path( extdata.path, paste( filenames, ".xz", sep="" ) ), xzuncompress )

# Reading the file...
fdta <- readFasta(in.file=file.path(extdata.path,filenames))

# ...and compressing it again
pth <- lapply( file.path( extdata.path, filenames ), xzcompress )

# Plotting and printing the Fasta object
plot(fdta)
summary(fdta)
str(fdta)

# Writing the Fasta object to a new file
writeFasta(fdta,out.file="Delete_me.fsa")

Run the code above in your browser using DataLab